var app = getApp(), api = require("../../../api.js");
var qqmapsdk;
Page({
    data: {
      page: 1,
      limit: 10,
      commentPage: 1,
      commentLimit: 15,
      folkItem: null,
      commentList: [],
      nowAddress: '湖南省长沙市天心区雀园路',
      collarStatus: 0,
      lineClamp: !0,
      btnText: '显示全文',
      btnShow: !1,
      news1: '这里的风景真好看这里的风景真好看这里的风景真好看这里的风景真好看这里的风景真好看这里的风景真好看',
      news2: '对呀！',
      content: '如果你无法简洁的表达你的想法，那只说明你还不够了解它；如果你无法简洁的表达你的想法，那只说明你还不够了解它；如果你无法简洁的表达你的想法，那只说明你还不够了解它； -- 阿尔伯特·爱因斯坦'
    },
    onLoad: function(option) {
      var that = this;
      var item = JSON.parse(option.folk_item)
      that.judgeHeight();
      this.setData({folkItem: item});
      this.getComentListByID(item.id);
    },
    // getFolkList: function (option) {
    //   var that = this;
    //   var item = option.folk_item;
    //   that.getComentListByID(item.id).then(data => {
    //     var tempObj = item;
    //     tempObj.comments = data.comments;
    //     if (data.comments.length == that.data.commentLimit) {
    //       tempObj.hasMore = true
    //     }
    //     that.setData({
    //       folkList: that.data.folkList.concat([tempObj])
    //     });
    //   });
    // },
    getComentListByID: function (folkID) {
      var that = this;
      var data = {
        page: this.data.commentPage,
        limit: this.data.commentLimit,
        folks_id: folkID
      };
      wx.showLoading({
        title: "加载中..."
      });
      app.request({
        url: api.folk.comments,
        data: data,
        success: function (res) {
          if (res.code == 0) {
            var comments = res.data.comments;
            that.setData({commentList: that.data.commentList.concat(comments)});
          }
        },
        fail: function (err) {
          wx.showToast({
            title: '获取主题评论失败',
            image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
          });
        },
        complete: function (d) {
          wx.hideLoading();
        }
      });
    },
    changeArticle: function(e){
      var that = this;
      if (that.data.lineClamp){
        that.setData({
          lineClamp: !1,
          btnText: '隐藏显示'
        });
      }else{
        that.setData({
          lineClamp: !0,
          btnText: '全文显示'
        });
      }
    },
    judgeHeight: function(e){
      var that = this;
      var query = wx.createSelectorQuery();
      // query.select('.article-cont').boundingClientRect()
      // query.exec(function (res) {
      //   //res就是 所有标签为mjltest的元素的信息 的数组
      //   if(res[0].height > 80){
      //     that.setData({
      //       btnShow: !0
      //     });
      //   }
      // })
    },
    previewImage: function(e){
      var that = this;
      var url = e.currentTarget.dataset.url;
      wx.previewImage({
        urls: [url] // 需要预览的图片http链接列表
      })
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
      this.setData({
        commentPage: this.data.commentPage + 1
      });
      this.getComentListByID(this.data.folkItem.id);
    },
    onShareAppMessage: function() {}
});